package com.intech.android.demo.cms.decorators;

import com.intech.android.demo.cms.bo.AudioContent;
import com.intech.android.demo.cms.bo.Group;
import com.intech.android.demo.cms.bo.Region;
import com.intech.android.demo.cms.common.Constants;
import com.intech.android.demo.cms.enums.Status;
import com.sun.org.apache.bcel.internal.classfile.Constant;
import org.apache.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

public class AudioContentDecorator
{
    private static final Logger log = Logger.getLogger(AudioContentDecorator.class);

    private String ad_id;
    private String category;
    private String name;
    private String advertiser;
    private String description;
    private List<String> viewingGroups;
    private List<String> regions;
    private String budget;
    private String paymentRate;
    private String status;


    public AudioContentDecorator(AudioContent audioContent)
    {
        ad_id = audioContent.getId().toString();
        category = audioContent.getCategory().getName();
        name = audioContent.getName();
        advertiser = audioContent.getAdvertiser();
        description = audioContent.getDescription();
        viewingGroups = new ArrayList<String>();
        regions = new ArrayList<String>();
        for (Group group : audioContent.getGroups())
        {
            viewingGroups.add(group.getName());
        }

        for (Region region : audioContent.getRegions())
        {
            regions.add(region.getName());
        }
        Double contentBudget = audioContent.getBudget();
        if (contentBudget == null)
        {
            budget = Constants.Settings.EMPTY_STRING;
            status = Status.Inactive.getMessage();
        }
        else
        {
            budget = contentBudget.toString();
            if (contentBudget < Constants.Logic.MIN_BUDGET)
            {
                status = Status.Inactive.getMessage();
            }
            else
            {
                status = Status.Active.getMessage();
            }
        }


        paymentRate = audioContent.getPayment() != null ? audioContent.getPayment().toString() : "";
    }

    public String getStatus()
    {
        return status;
    }

    public String getAdvertiser()
    {
        return advertiser;
    }

    public void setAdvertiser(String advertiser)
    {
        this.advertiser = advertiser;
    }


    public String getPaymentRate()
    {
        return paymentRate;
    }

    public void setPaymentRate(String paymentRate)
    {
        this.paymentRate = paymentRate;
    }

    public String getBudget()
    {

        return budget;
    }

    public void setBudget(String budget)
    {
        this.budget = budget;
    }

    public String getRegions()
    {
        String regionStr = "";
        for (String region : regions)
        {
            regionStr += region + ",";
        }
        return regionStr;
    }


    public String getViewingGroups()
    {
        String viewingGroupsStr = "";
        for (int i = 0; i < this.viewingGroups.size(); i++)
        {
            viewingGroupsStr += this.viewingGroups.get(i);
            if (i < this.viewingGroups.size() - 1)
            {
                viewingGroupsStr += ",";
            }
        }
        return viewingGroupsStr;
    }

    public void setViewingGroups(String viewingGroupsStr)
    {
        viewingGroups = new ArrayList<String>();
        String tempString = "";
        for (int i = 0; i < viewingGroupsStr.length(); i++)
        {
            if (viewingGroupsStr.charAt(i) != ',')
            {
                tempString += viewingGroupsStr.charAt(i);
            }
            else
            {
                viewingGroups.add(tempString);
                tempString = "";
            }
        }
    }

    public String getDescription()
    {

        return description;
    }

    public void setDescription(String description)
    {
        this.description = description;
    }

    public String getName()
    {

        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public String getCategory()
    {

        return category;
    }

    public void setCategory(String category)
    {
        this.category = category;
    }

    public String getAd_id()
    {

        return ad_id;
    }

    public void setAd_id(String ad_id)
    {
        this.ad_id = ad_id;
    }

    public String getRemaining()
    {
        Double remaining = Double.parseDouble(budget) / 2;
        return remaining.toString();
    }

    public void setRemaining(String remaining)
    {
    }
}
